package com.ysucode.dao.oj;

import com.ysucode.domain.Problem;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ProblemMapper {
    //查询所有题目列表
    @Select("select id,title,level,keyword,description from oj_problem")
    List<Problem> getAll();

    //根据Id查询一个java题目
    @Select("select oj_problem.id,title,level,keyword,description,template,test,example " +
            "from oj_problem inner join oj_problem_java " +
            "on oj_problem.id=oj_problem_java.id and oj_problem.id=#{id} limit 1")
    Problem getJavaById(@Param("id") int id);

    //插入一个题目
    @Insert("insert into oj_problem values(null,#{title},#{level},#{keyword},#{description})")
    Integer addProblem(Problem problem);

    //插入一个具体的Java题目
    @Insert("insert into oj_problem_java values(#{id},#{example},#{template},#{test})")
    Integer addJavaProblem(Problem problem);

    @Select("select max(id) from oj_problem")
    Integer getLastId();
}
